//@author A0101200R

package logic;

public class ScheduleHelp {
	
	// list of constants 
	private static final String NEW_LINE = "\n";
	private static final String EMPTY_STRING = "";
	
	// list of direct help commands
	private static final String ADD = "add";
	private static final String DELETE = "delete";
	private static final String MODIFY = "modify";
	private static final String UNDO = "undo";
	private static final String REDO = "redo";
	private static final String SEARCH = "search";
	private static final String SORT = "sort";
	private static final String DISPLAY = "display";
	private static final String MARK = "mark";
	
	// list of messages
	private static final String MSG_ADD = "Add Commands:" + NEW_LINE;
	private static final String MSG_DELETE = "Delete Command:" + NEW_LINE;
	private static final String MSG_MODIFY = "Modify Command:" + NEW_LINE;
	private static final String MSG_UNDO = "Undo Command:" + NEW_LINE;
	private static final String MSG_REDO = "Redo Command:" + NEW_LINE;
	private static final String MSG_SEARCH = "Search Commands:" + NEW_LINE;
	private static final String MSG_SORT = "Sort Commands:" + NEW_LINE;
	private static final String MSG_DISPLAY = "Display Commands:" + NEW_LINE;
	private static final String MSG_MARK = "Mark Commands:" + NEW_LINE;
	private static final String MSG_HElP = "Help Command:" + NEW_LINE;
	
	// list of error messages
	private static final String ERROR_WRONG_INPUT = "Error! The input after help is wrong.";

	// list of add commands
	private static final String COMMAND_ADD_TIMED = "add {taskName} on {ddmmyyyy} from {startTime} to {endTime}";
	private static final String COMMAND_ADD_DATELINE1 = "add {taskName} on {ddmmyyyy} by {endTime}";
	private static final String COMMAND_ADD_DATELINE2 = "add {taskName} on {ddmmyyyy}";
	private static final String COMMAND_ADD_FLOATING = "add {taskName}";
	private static final String COMMAND_ADD_ALTERNATIVE = "NOTE: {ddmmyyyy} can be replaced by" + NEW_LINE 
															+ "eg  {today} or {monday} or {21 apr} or {21 apr 2014}";
	
	// list of delete command
	private static final String COMMAND_DELETE = "delete {taskNumber}";
	
	// list of modify command
	private static final String COMMAND_MODIFY = "modify {taskNumber} n {newEventName} d {newEventDate} st {newEventStartTime} et {newEventEndTime}";
	private static final String COMMAND_MODIFY_DETAILS = " n : taskName, d : taskDate, st : startTime, et: endTime ";
	private static final String COMMAND_MODIFY_NOTE = "NOTE: You can choose to modify 1-4 parameters.";
	
	// list of undo command
	private static final String COMMAND_UNDO = "undo";
	
	// list of redo command
	private static final String COMMAND_REDO = "redo";
	
	// list of search commands
	private static final String COMMAND_SEARCH_KEYWORD = "search {keyword}";
	private static final String COMMAND_SEARCH_DATE = "search {ddmmyyyy}";
	private static final String COMMAND_SEARCH_DATERANGE = "search {ddmmyyyy ddmmyyyy}";
	private static final String COMMAND_SEARCH_TYPE = "search {timed} or search {deadline} or search {floating}";
	
	// list of sort commands
	private static final String COMMAND_SORT_ALPHABETICAL = "search -sa or display -sa (alphabetical order)";
	private static final String COMMAND_SORT_URGENCY = "search -su or display -su (urgency)";
	private static final String COMMAND_SORT_TYPE = "search -st or display -st (type)";
	
	// list of display commands
	private static final String COMMAND_DISPLAY_TODAY = "display (tasks on the day itself)";
	private static final String COMMAND_DISPLAY_ALL = "display all";
	private static final String COMMAND_DISPLAY_DONE = "display done";
	private static final String COMMAND_DISPLAY_UNDONE = "display undone";
	private static final String COMMAND_DISPLAY_INDEX = "display {index} (show details of the particular task)";
	private static final String COMMAND_DISPLAY_NOTE = "NOTE: if there is more than 5 tasks available, only the name will be shown.";
	
	// list of mark command
	private static final String COMMAND_MARK_DONE = "mark {keyword} done";
	private static final String COMMAND_MARK_UNDONE = "mark {keyword} undone";
	
	// help command
	private static final String COMMAND_HELP_GENERAL = "help";
	private static final String COMMAND_HELP_SPECIFIC = "help {command}";
	
	// a string to store all the commands in lifeShelf.
	private static String listOfCommands = null;

	// constructor 
	public ScheduleHelp() {
	}
	
	protected String helpAdd() {
		String add = MSG_ADD 
					+ COMMAND_ADD_TIMED + NEW_LINE 
					+ COMMAND_ADD_DATELINE1 + NEW_LINE 
					+ COMMAND_ADD_DATELINE2 + NEW_LINE
					+ COMMAND_ADD_FLOATING + NEW_LINE
					+ COMMAND_ADD_ALTERNATIVE + NEW_LINE;
		
		return add; 
	}
	
	protected String helpDelete() {
		return MSG_DELETE + COMMAND_DELETE + NEW_LINE;
	}
	
	protected String helpModify() {
		String modify = MSG_MODIFY 
				+ COMMAND_MODIFY + NEW_LINE
				+ COMMAND_MODIFY_DETAILS + NEW_LINE
				+ COMMAND_MODIFY_NOTE + NEW_LINE;
		
		return modify;
	}
	
	protected String helpUndo() {
		return MSG_UNDO + COMMAND_UNDO + NEW_LINE;
	}
	
	protected String helpRedo() {
		return MSG_REDO + COMMAND_REDO + NEW_LINE;
	}
	
	protected String helpSearch() {
		String search = MSG_SEARCH
						+ COMMAND_SEARCH_KEYWORD + NEW_LINE
						+ COMMAND_SEARCH_DATE + NEW_LINE
						+ COMMAND_SEARCH_DATERANGE + NEW_LINE
						+ COMMAND_SEARCH_TYPE + NEW_LINE;
		
		return search;
	}
	
	protected String helpSort() {
		String sort = MSG_SORT
					  + COMMAND_SORT_ALPHABETICAL + NEW_LINE
					  + COMMAND_SORT_URGENCY + NEW_LINE
					  + COMMAND_SORT_TYPE + NEW_LINE;
		
		return sort;
	}
	
	protected String helpDisplay() {
		String display = MSG_DISPLAY 
					+ COMMAND_DISPLAY_TODAY + NEW_LINE
					+ COMMAND_DISPLAY_ALL + NEW_LINE
					+ COMMAND_DISPLAY_DONE + NEW_LINE
					+ COMMAND_DISPLAY_UNDONE + NEW_LINE
					+ COMMAND_DISPLAY_INDEX + NEW_LINE
					+ COMMAND_DISPLAY_NOTE + NEW_LINE;
		
		return display;
	}
	
	protected String helpMark() {
		String mark = MSG_MARK
				+ COMMAND_MARK_DONE + NEW_LINE
				+ COMMAND_MARK_UNDONE + NEW_LINE;
		
		return mark;
	}
	
	protected String helpHelp() {
		String help = MSG_HElP 
				+ COMMAND_HELP_GENERAL + NEW_LINE
				+ COMMAND_HELP_SPECIFIC;
		return help;
	}
	
	/**
	 * Provides a list commands' formats for the user. 
	 * If the user type in "help", the list of all the commands' formats will be returned.
	 * If the user type in "help add", only the list of add command formats will be returned.
	 * 
	 * @param userCommandDetails
	 * @return listOfCommands
	 */
	public String helpList(String userCommandDetails) {
		assert userCommandDetails != null;
		
		String add = helpAdd() + NEW_LINE;
		String delete = helpDelete() + NEW_LINE;
		String modify = helpModify() + NEW_LINE;
		String undo = helpUndo() + NEW_LINE;
		String redo = helpRedo() + NEW_LINE;
		String search = helpSearch() + NEW_LINE;
		String sort = helpSort() + NEW_LINE;
		String display = helpDisplay() + NEW_LINE;
		String mark = helpMark() + NEW_LINE;
		String help = helpHelp() + NEW_LINE;
		
		switch (userCommandDetails) {
		
		case EMPTY_STRING:
			listOfCommands = add + delete + modify 
							+ undo + redo + search + sort 
							+ display + mark + help;	
			break;
		case ADD:
			listOfCommands = add.trim();
			break;
		case DELETE:
			listOfCommands = delete.trim();
			break;	
		case MODIFY:
			listOfCommands = modify.trim();
			break;	
		case UNDO:
			listOfCommands = undo.trim();
			break;
		case REDO:
			listOfCommands = redo.trim();
			break;
		case SEARCH:
			listOfCommands = search.trim();
			break;
		case SORT:
			listOfCommands = sort.trim();
			break;
		case DISPLAY:
			listOfCommands = display.trim();
			break;
		case MARK:
			listOfCommands = mark.trim();
			break;
		default:
			listOfCommands = ERROR_WRONG_INPUT;
			
		}
		
		return listOfCommands;
	}
}
